/****************************************************************************
* copyright            : (C) 2009 William Viana Soares <vianasw@gmail.com>  *
*****************************************************************************/

/****************************************************************************
*                                                                           *
*   This program is free software; you can redistribute it and/or modify    *
*   it under the terms of the GNU General Public License as published by    *
*   the Free Software Foundation; either version 2 of the License, or       *
*   (at your option) any later version.                                     *
*                                                                           *
*****************************************************************************/


#ifndef QUERYMAKER_H
#define QUERYMAKER_H

#include <boost/asio.hpp>
#include <string>

namespace ConciseQSR
{
using boost::asio::ip::tcp;
using namespace std;

/**
* @class QueryMaker
* @short A class to communicate with SparQ
*/
class QueryMaker
{
public:
    QueryMaker( boost::asio::io_service &io_service, string host = "localhost", string port = "4242" );
    ~QueryMaker();

    string aClosure( const string &constraints ) const;
    string computeRelation( string op, const string &baseRelation ) const;
    string computeHomming( const string &baseRelation ) const { return computeRelation( "hm", baseRelation ); };
    string computeHommingInverse( const string &baseRelation ) const{ return computeRelation( "hmi", baseRelation ); };
    string computeShortcut( const string &baseRelation ) const{ return computeRelation( "sc", baseRelation ); };
    string computeShortcutInverse( const string &baseRelation ) const{ return computeRelation( "sci" , baseRelation ); };
    string computeInverse( const string &baseRelation ) const{ return computeRelation( "inv", baseRelation ); };
    string makeQuery( const string &command ) const;
    string qualifyPoints( const string &points ) const;
    string qualifyPointsAll( const string &points ) const;
    
private:
    string m_host;
    string m_port;
    
    boost::shared_ptr< boost::asio::io_service > m_io_service;
    boost::shared_ptr< boost::asio::streambuf > m_response;
    boost::shared_ptr< boost::asio::streambuf > m_request;
    boost::shared_ptr< tcp::socket > m_socket;

};
}// namespace ConciseQSR

#endif
